package ter.find.pattern;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

public class ModelMotif extends AbstractTableModel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public int supValue=0;
	private List<Motif> motif=new ArrayList<Motif>();
	private List<Motif> motifString=new ArrayList<Motif>();
	private final String[] title = {"Motifs","Id séquence","Support","Séquence/Total"};
	private int attribMotif=4;
	String Sequences;
	int minSup;
	int idSequences;
	String motifs;
	public String[][] data;
	String itemString = null;
	String idString=null;

	
	public String getSequences() {
		return Sequences;
	}

	public void setSequences(String sequences) {
		Sequences = sequences;
	}

	public int getMinSup() {
		return minSup;
	}

	public void setMinSup(int minSup) {
		this.minSup = minSup;
		supValue=minSup;
	}

	public int getIdSequences() {
		return idSequences;
	}

	public void setIdSequences(int idSequences) {
		this.idSequences = idSequences;
	}

	public String getMotifs() {
		return motifs;
	}

	public void setMotifs(String motifs) {
		this.motifs = motifs;
	}
	

	public void setMotif(List<Motif> motif) {
		this.motif = motif;
	}
	

	public List<Motif> getMotif() {
		return motif;
	}
	
	public int getSize(){
		return motif.size();
	}
	
	
	
	public String[][] getData() {
		
		return data;
	}

	public void setData(String[][] data) {
		this.data = data;
	}

	/*Recuperations des données dans la listes de motifs*/
	//Liste des items
	public List<String> itemList(Motif m){
		return m.getItem();
	}
	
	//Liste des idSequences
	public List<Integer> seqList(Motif m){
		return m.getIdseq();
	}
	
	//Support d'un motif
	public String supMotif(Motif m){
		return m.getSupport();
	}
	
	//Nombre de motifs
	public String countMotif(Motif m){
		return m.getCount();
	}

	
	public ModelMotif(List<Motif> motif1) {
		System.out.println("Get motiff");
		
		for(int i=0;i<motif1.size();i++){
			Motif m=motif1.get(i);
			List<String> listItem=new ArrayList<String>();listItem=m.getItem();
			List<Integer> listId=new ArrayList<Integer>();listId= m.getIdseq();
			String sup=m.getSupport();
			String count=m.getCount();
			
			for(int j=0;j<attribMotif;j++){
				if(j==0){
					System.out.println(listItem.toString());
					itemString=listItem.toString();
								
				}
				if(j==1){
					System.out.println(listId.toString());
					idString=listId.toString();
					
				}
				if(j==2){
					System.out.println(sup);
					
				}
				if(j==3){
					System.out.println(count);
					
				}
			}
			//Create a new motif à chaque boucle 
			motifString.add(new Motif(new Boolean(false),itemString, idString, sup,count));
		}
	}
	
	public String[][] addMotif(List<Motif> motif1){
		System.out.println("Get motiff");
		
		for(int i=0;i<motif1.size();i++){
			Motif m=motif1.get(i);
			List<String> listItem=new ArrayList<String>();listItem=m.getItem();
			List<Integer> listId=new ArrayList<Integer>();listId= m.getIdseq();
			String sup=m.getSupport();
			String count=m.getCount();
			//Value to String
			
			data=new String[motif1.size()][attribMotif];
			for(int j=0;j<attribMotif;j++){
				if(j==0){
					System.out.println(listItem.toString());
					itemString=listItem.toString();
					data[i][j]=listItem.toString();					
				}
				if(j==1){
					System.out.println(listId.toString());
					idString=listId.toString();
					data[i][j]=listId.toString();	
				}
				if(j==2){
					System.out.println(sup);
					data[i][j]=sup;
				}
				if(j==3){
					System.out.println(count);
					data[i][j]=count;
				}
			}
			//Create a new motif à chaque boucle 
			motifString.add(new Motif(new Boolean(false),itemString, idString, sup,count));
		}
		
		
		return data;
	}
	
	
	public ModelMotif() {
		super();
		this.addMotif();
	}
	
	public void addMotif(){
		motif.add(new Motif(new Boolean(false),"1", "<C,U,D,{U}>", "0.2","d"));
		motif.add(new Motif(new Boolean(false),"2", "<C,D,U>", "0.11","dd"));
		motif.add(new Motif(new Boolean(false),"3", "<{U},{C,C,U}>", "0.5","ddd"));
		motif.add(new Motif(new Boolean(false),"4", "<C,D>", "0.02","4444"));
	}
	

	@Override
	public int getColumnCount() {
		// TODO Auto-generated method stub
		return title.length;
	}

	@Override
	public int getRowCount() {
		// TODO Auto-generated method stub
		return motif.size();
	}
	
	public String getColumnName(int columnIndex) {
        return title[columnIndex];
    }

	@Override
	  public Object getValueAt(int rowIndex, int columnIndex) {
        switch(columnIndex){
            case 0:
                return motif.get(rowIndex).getIdMotifs();
            case 1:
                return motif.get(rowIndex).getMotif();
            case 2:
                return motif.get(rowIndex).getSupport();
            
            default:
                return null; //Ne devrait jamais arriver
        }
    }
	
	public void addAmi(Motif m) {
        motif.add(m);
 
        fireTableRowsInserted(motif.size() -1, motif.size() -1);
    }
 
    public void removeAmi(int rowIndex) {
        motif.remove(rowIndex);
 
        fireTableRowsDeleted(rowIndex, rowIndex);
    }


}
